package main

import (
	"log"
	"rabbitmq"
)

func main() {
	conn := rabbitmq.NewConn()
	defer conn.Close()

	channel, err := conn.Channel()
	rabbitmq.FailOnError(err, "Channel err")

	err = channel.ExchangeDeclare("normal_exchange", "direct", false, false, false, false, nil)
	rabbitmq.FailOnError(err, "ExchangeDeclare err")

	q, err := channel.QueueDeclare("normal_queue", false, false, false, false, nil)
	rabbitmq.FailOnError(err, "QueueDeclare err")

	err = channel.QueueBind(q.Name, "normal", "normal_exchange", false, nil)
	rabbitmq.FailOnError(err, "QueueBind err")

	messages, err := channel.Consume(q.Name, "", true, false, false, false, nil)
	rabbitmq.FailOnError(err, "Consume err")

	var forever chan struct{}

	go func() {
		for msg := range messages {
			log.Printf("Received a message: %s", msg.Body)
		}
	}()

	log.Printf(" [*] Waiting for messages. To exit press CTRL+C")
	<-forever
}
